Skip to content

Fix MSSQL JDBC "database=" parameter not extracting db.name, issue 19024#19029

Open
hwxy233 wants to merge 14 commits into
open-telemetry:mainfrom
hwxy233:bugfix-mssql-jdbc-database-param
Open

Fix MSSQL JDBC "database=" parameter not extracting db.name, issue 19024#19029
hwxy233 wants to merge 14 commits into
open-telemetry:mainfrom
hwxy233:bugfix-mssql-jdbc-database-param

Conversation

@hwxy233

@hwxy233 hwxy233 commented Jun 17, 2026

Copy link
Copy Markdown

For this issue The Java agent did not detect the database name, I want to create a pr.

The Microsoft SQL Server JDBC driver supports both 'databaseName' and 'database' as connection property names for specifying the database name. However, the URL parser only checked for 'databasename' (after lowercasing), causing jdbc:sqlserver://...;database=xxx URLs to not extract the db.name attribute.

This commit adds 'database' as a fallback key in:

  • ParseContext.applyCommonParams() - used by MssqlUrlParser
  • JtdsUrlParser.parse() - used by jTDS driver

Additional test cases cover the 'database=' parameter for both sqlserver and jtds URL formats.

The Microsoft SQL Server JDBC driver supports both 'databaseName' and
'database' as connection property names for specifying the database name.
However, the URL parser only checked for 'databasename' (after
lowercasing), causing jdbc:sqlserver://...;database=xxx URLs to not
extract the db.name attribute.

This commit adds 'database' as a fallback key in:
- ParseContext.applyCommonParams() - used by MssqlUrlParser
- JtdsUrlParser.parse() - used by jTDS driver

Additional test cases cover the 'database=' parameter for both
sqlserver and jtds URL formats.
@hwxy233 hwxy233 requested a review from a team as a code owner June 17, 2026 11:42
Copilot AI review requested due to automatic review settings June 17, 2026 11:42
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 17, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: hwxy233 / name: hwxy233 (2e437e7)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR adds support for the database= connection string property as an alias for databaseName in SQL Server and jTDS JDBC URL parsing.

Changes:

  • Adds fallback logic in ParseContext.applyCommonParams to check the database parameter when databasename is null or empty.
  • Updates JtdsUrlParser to also resolve the database parameter as a fallback when no path-based database name is found.
  • Adds test cases covering the database= alias in both standard SQL Server and jTDS connection URLs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
ParseContext.java Falls back to database param if databasename is null or empty in applyCommonParams.
JtdsUrlParser.java Adds database as a fallback parameter when resolving database name from jTDS URL params.
JdbcConnectionUrlParserTest.java Adds test cases for the database= alias in SQL Server and jTDS URLs.

…th ParseContext

Previously JtdsUrlParser used containsKey() which would accept an empty
'databasename=' value and not fall through to the 'database' fallback.
Now uses the same null/empty check pattern as
ParseContext.applyCommonParams: if databasename is absent or empty, fall
through to the database parameter.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

hwxy233 added 3 commits June 17, 2026 21:22
…method

Replace duplicated resolution logic in both
ParseContext.applyCommonParams() and JtdsUrlParser.parse() with a single
ParseContext.applyDatabaseNameParam(Map) method that resolves the
database name from URL parameters, trying 'databasename' first and
falling back to 'database'.
@hwxy233 hwxy233 requested a review from Copilot June 17, 2026 13:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

@hwxy233 hwxy233 requested a review from Copilot June 17, 2026 13:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

hwxy233 added 3 commits June 18, 2026 11:25
… parsing in MssqlUrlParser

Addresses two review comments:

1. Deduplicate getDatabaseNameParam: The method was copied verbatim in both
   MssqlUrlParser and JtdsUrlParser. Moved to UrlParsingUtils as a shared
   static helper, consistent with other utilities like extractSubtype and
   splitQuery already in that class.

2. Eliminate redundant URL parsing: MssqlUrlParser was parsing semicolon
   parameters twice — once in applyCommonParams and again in
   applyDatabaseAliasParam. Now extract the params map once in parse(),
   then pass it to both applyCommonParams (new map-based overload) and
   applyDatabaseAliasParam.

Additionally, applyDatabaseAliasParam no longer re-extracts params from
the URL string.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

…e from MssqlUrlParser

Refactor suggested by review comment: instead of duplicating the
applyCommonParams logic as a private method in MssqlUrlParser, add a
public overload ParseContext.applyCommonParams(Map<String, String>)
that accepts a pre-parsed parameter map. MssqlUrlParser now calls
ctx.applyCommonParams(urlParams) directly, eliminating the near-copy.

The original applyCommonParams(String, String, String) now delegates to
the new map-based overload to ensure both versions stay in sync.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants